package com.aabbc.jdbc.scheduler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * TestScheduler
 *
 * @author: <a href="mailto:chenfenghai@oristartech.com">chenfenghai</a>
 * @version: 1.0
 * @date: 2019-11-19 16:10
 */
@Slf4j
@Component
public class TestScheduler {

    @Autowired
    JdbcTemplate jdbcTemplate;

    @Scheduled(cron = "0/5 * * * * *")
    public void scheduled(){
        List<Map<String, Object>> list = jdbcTemplate.queryForList("select * from U_USER_INFO");
        if(list != null){
            list.forEach(System.out::println);
        }
        log.info("=====>>>>>使用cron  {}",System.currentTimeMillis());
    }

    @Scheduled(fixedRate = 5000)
    public void scheduled1() {
        log.info("=====>>>>>使用fixedRate{}", System.currentTimeMillis());
    }

    @Scheduled(fixedDelay = 5000)
    public void scheduled2() {
        log.info("=====>>>>>fixedDelay{}",System.currentTimeMillis());
    }
}
